import * as TYPES from '../actions/actionTypes'
const initialState = {
    isLoading: true,
    userInfo: null,
    tenantId:'',
    loginState: false,
    roleList: [],
    permission: [],
    token: null,
    openid: null,
    loginDisable: false
}

export default function user(state = initialState, action) {
    switch (action.type) {
        case TYPES.LOGIN_SUCCESS:
            return {
                ...state,
                openid: action.openid,
                loginDisable: false,
                isLoading:false,
            };
        case TYPES.LOGIN_ING:
            return {
                ...state,
                loginDisable: true,
                isLoading:false,
            };
        case TYPES.LOGIN_FAIL:
            return {
                ...state,
                loginDisable: false,
                isLoading:false
            };
        case TYPES.GO_LOGIN:
            return {
                ...state,
                isLoading: false
            }

        case TYPES.GETTOKEN_ING:
            return {
                ...state,
                isLoading:true
            }
        case TYPES.GETTOKEN_FAIL:
            return {
                ...state,
                isLoading:false
            } 
        case TYPES.GETTOKEN_SUCCESS:
            return {
                ...state,
                isLoading:false,
                token:action.token,
                userInfo:action.userInfo,
                tenantId:action.TenantId,
                roleList:action.roleList,
                permission:action.permission
            }       
        default:
            return state
    }
}

